package com.lenovo.vod.player.callback;

import com.lenovo.vod.player.Constant;
import com.lenovo.vod.player.Engine;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class TouchListener implements View.OnTouchListener {
	private Engine mEngine;
	private float x1 = 0, x2 = 0, y1 = 0, y2 = 0;

	public TouchListener(Engine engine) {
		mEngine = engine;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		Log.d(Constant.TAG, "onTouch called[action: " + event.getAction() + "]");

		switch (event.getAction()) {

		case MotionEvent.ACTION_DOWN:
			x1 = event.getX();
			y1 = event.getY();

			break;
		case MotionEvent.ACTION_UP:
			x2 = event.getX();
			y2 = event.getY();

			if (y2 > y1 && y2 - y1 > Math.abs(x2 - x1) * 2) {
				mEngine.hideController();
			} else if (y2 < y1 && y1 - y2 > Math.abs(x2 - x1) * 2) {
				mEngine.showControllerTimed();
			} else if (y2 == y1 && x2 == x1) {
				mEngine.pauseOrStart();

			}

			x1 = y1 = x2 = y2 = 0;
			break;
		}
		return true;
	}
}